<template>
	<div class="content">
		<!-- 终极押题页 -->
		<!-- 面包屑导航 -->
		<Crumbs :item="crumbsItem" @crumbsClick="crumbsClick"></Crumbs>
		<!-- 列表页 -->
		<paperItem :list="paperList" :modeFlase="modeFlase" v-if="show == 1 && paperList" @paperClick="skipResult" @startAnswer="clickStart"></paperItem>
		<!-- Question题目列表     CountVO答题卡数据  isRecitation是否背题模式  isCorrecting 是否批改题目-->
		<answer
			ref="answer"
			v-if="show == 11"
			@sumitSucess="sumitSucess"
			:CorrectCount="correctCount"
			:ErrorCount="errorCount"
			:Question="Question"
			:isCountDown="false"
			:CountVO="CountVO"
			:isRecitation="isRecitation"
			:isCorrecting="isCorrecting"
			:Formalexam="Formalexam"
			:Paper="Paper"
			:topicNumber="Paper.number"
			updateHis="updateExamHistory"
		></answer>
		<!-- <PgCom v-if="show==1 && paperPages!=0" :total_page="paperPages" :show_page="pageNo" @func="fenye1"></PgCom> -->
		<PgCom v-if="show == 1 && total > pageSize" :total="total" :pageNo="pageNo" :pageSize="pageSize" @pageNoChange="pageNoChange"></PgCom>
		<!-- 成绩页面 -->
		<ScoreModule v-if="show == 2" :data="transcript" @againBtn="clickStart" @viewWrong="viewWrong"></ScoreModule>
		<Popup v-if="subModalShow2" :mold="2" title="正在交卷中..."></Popup>
	</div>
</template>

<script>
import exam from '../../../mixins/exam.js';
export default {
	name: 'FinalQues',
	components: {},
	mixins: [exam],
	data() {
		return {
			show: 1, //显示模块
			pageNo: 1, //页码
			pageSize: 6,
			paperPages: 0, //页数
			total: 0,
			paperList: null, //列表
			crumbsItem: [{ name: '终极押题', url: 1 }], //面包屑导航
			papername: '',
			transcript: {},
			CountVO: {}, //题卡
			Question: [], //题目
			correctCount: 0, //正确数量
			errorCount: 0, //错误数量
			Paper: {}, //传递试卷信息
			isRecitation: false, //是否背题模式
			isCorrecting: false, //是否批改题目
			Formalexam: false,
			subModalShow2: false,
			modeFlase:false//开始考卷提示弹窗
		};
	},
	created() {
		this.getFinalQues(this.pageNo);
	},
	mounted() {
		window.addEventListener('beforeunload', e => {
			if (this.refresh.clickDis) {
				this.beforeunloadHandler(e);
			}
		});
	},
	destroyed() {
		window.addEventListener('beforeunload', e => {
			if (this.refresh.clickDis) {
				this.beforeunloadHandler(e);
			}
		});
	},
	methods: {
		beforeunloadHandler(e) {
			e = e || window.event;
			if (this.show == 11) {
				if (e) {
					e.returnValue = '正在更新数据';
				}
				this.$refs.answer.updateHistoryHander('updateExamHistory');
				return;
			}
		},
		crumbsClick(type) {
			//导航切换事件
			this.show = type;
			if (type == 1) {
				this.crumbsInit();
				this.getFinalQues(this.pageNo);
			}
		},
		crumbsInit() {
			// 导航默认
			this.crumbsItem = [{ name: '终极押题', url: 1 }];
		},
		skipResult(e) {
			this.papername = e.papername;
			this.Paper = e; //试卷信息带给答题页
			let val1 = e.upid,
				val3 = e.status;
			if (val3 === 2) {
				this.crumbsInit();
				// 展示成绩页
				let navLi = {
					name: this.papername,
					url: 2
				};
				this.crumbsItem.push(navLi);
				this.show = 2;
				this.axios
					.get('/web/student/home/getTranscript', {
						params: {
							upid: val1
						}
					})
					.then(res => {
						this.transcript = res;
					});
			}
		},
		pageNoChange(val) {
			this.getFinalQues(val);
		},
		sumitSucess(e) {
			//交卷成功
			this.show = 2;
			this.Paper.status = 2;
			this.Paper.upid = e;
			this.skipResult(this.Paper);
		},
		//获取终极押题列表
		getFinalQues(val) {
			// this.papers = [];
			this.show = 1;
			this.axios
				.post('/web/student/home/getPropositionList', {
					pageNo: val,
					pageSize: this.pageSize,
					papertype: 2
				})
				.then(res => {
					this.paperList = res.list;
					this.total = res.total;
					this.paperPages = res.pages;
				});
		},
		clickStart(e) {
			if (e.papername) {
				this.papername = e.papername;
			}
			if (e.restart) {
				//再考一次进入
				this.Paper.minutes = e.duration;
				this.Paper.duration = 0;
				this.Paper.number = 1;
			}
			const pageData = {
				paperid: e.paperid
			};
			this.modeFlase=true;
			this.crumbsInit();
			this.setCrumbs(this.papername, 11);
			this.isRecitation = false; //不是背题模式
			this.isCorrecting = false;
			this.Formalexam = true;
			// 开始答题
			this.startAnswer(pageData);
		},
		setCrumbs(name, url) {
			this.crumbsInit();
			let navLi = {
				name: name,
				url: url
			};
			this.crumbsItem.push(navLi);
		},
		viewWrong(e) {
			const pageData = {
				paperid: this.Paper.paperid,
				upid: this.Paper.upid,
				isCorrect: e
			};
			// 查看错题
			this.Paper.number = 1;
			this.isRecitation = true;
			this.isCorrecting = true;
			this.autoCorrecting = true;
			this.viewWrongTopic(pageData);
		}
	}
};
</script>
